#!/bin/sh
#
# This is the script for generating files for a specific Dalton test job.
#
# For the .check file ksh or bash is preferred, otherwise use sh
# (and hope it is not the old Bourne shell, which will not work)
#
if [ -x /bin/ksh ]; then
   CHECK_SHELL='#!/bin/ksh'
elif [ -x /bin/bash ]; then
   CHECK_SHELL='#!/bin/bash'
else
   CHECK_SHELL='#!/bin/sh'
fi


#######################################################################
#  TEST DESCRIPTION
#######################################################################
cat > energy_direct_eri.info <<'%EOF%'
   energy_direct_eri
   -------------
   Molecule:         H2O
   Wave Function:    Direct SCF / cc-pVDZ
   Test Purpose:     Check energy calculated directly (using ERI)
                     and with symmetry
%EOF%

#######################################################################
#  MOLECULE INPUT
#######################################################################
cat > energy_direct_eri.mol <<'%EOF%'
basis
cc-pVDZ
Direct SCF calculation with/o symmetry
using ERI integral module
    Atomtypes=2
        8.    1 
O     0.0 -0.2249058930 0.0
        1.    2 
H     1.45235 0.899623 0.0
H    -1.45235 0.899623 0.0
%EOF%

#######################################################################
#  DALTON INPUT
#######################################################################
cat > energy_direct_eri.dal <<'%EOF%'
**DALTON INPUT
.RUn wAVE FUNCTION
.DiRECT
.RUNERI
**WAVE FUNCTIONS
.HF
**end of input
%EOF%
#######################################################################

 

#######################################################################

#######################################################################
#  CHECK SCRIPT
#######################################################################
echo $CHECK_SHELL >energy_direct_eri.check
cat >>energy_direct_eri.check <<'%EOF%'
log=$1

if [ `uname` = Linux ]; then
   GREP="egrep -a"
else
   GREP="egrep"
fi

# Symmetry:
CRIT1=`$GREP "Symmetry class found: C.2v." $log | wc -l`
CRIT2=`$GREP "The following symmetry elements were found: * X * Y" $log | wc -l`
#CRIT3=`$GREP "Symmetry operations: * 2" $log | wc -l`
CRIT3=1
CRIT4=`$GREP "Full point group is: * C.2v." $log | wc -l`
CRIT5=`$GREP "Represented as: * C2v" $log | wc -l`
CRIT6=`$GREP "Number of coordinates in each symmetry: * 3 * 2 * 3 * 1" $log | wc -l`
TEST[1]=`expr $CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4 \+ $CRIT5 \+ $CRIT6`
CTRL[1]=6
ERROR[1]="SYMMETRY NOT CORRECT"

# Direct:
CRIT1=`$GREP "Fock matrices are calculated directly" $log | wc -l`
CRIT2=`$GREP "without use of integrals on disk." $log | wc -l`
TEST[2]=`expr $CRIT1 \+ $CRIT2`
CTRL[2]=2
ERROR[2]="NOT A DIRECT CALCULATION"

# Huckel guess:
CRIT1=`$GREP "Initial occupation of symmetries is determined from extended Huckel guess." $log | wc -l`
CRIT2=`$GREP "Occupied SCF orbitals .* 3 * 1 * 1 * 0" $log | wc -l`
TEST[3]=`expr $CRIT1 \+ $CRIT2`
CTRL[3]=2
ERROR[3]="HUCKEL GUESS NOT CORRECT"

# SCF energy:
CRIT1=`$GREP "Final * HF energy: * \-76\.0256814839[0-9][0-9]" $log | wc -l`
TEST[4]=`expr $CRIT1`
CTRL[4]=1
ERROR[4]="SCF ENERGY NOT CORRECT"

PASSED=1
for i in 1 2 3 4
do 
   if [ ${TEST[i]} -ne ${CTRL[i]} ]; then
     echo "${ERROR[i]} ( test = ${TEST[i]}; control = ${CTRL[i]} ); "
     PASSED=0
   fi
done 

if [ $PASSED -eq 1 ]
then
  echo TEST ENDED PROPERLY
  exit 0
else
  echo THERE IS A PROBLEM 
  exit 1
fi

%EOF%
#######################################################################
